#include "Graphics/Color.hpp"
#include <sstream>
using::std::ostringstream;

namespace Graph
{

uint8_t Color::floatToByte(const float color)
{
    if (color >= 1.0f)
        return 255;
    else if (color <= 0.0f)
        return 0;
    else
        return uint8_t(255 * color);
}

Color::Color()
    : m_r(0), m_g(0), m_b(0), m_a(255)
{
}

Color::Color(const Color &other)
    : m_r(other.m_r), m_g(other.m_g), m_b(other.m_b), m_a(other.m_a)
{
}

Color::Color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a):
    m_r(r), m_g(g), m_b(b), m_a(a)
{
}

Color::Color(const float rf, const float gf, const float bf, const float af)
{
    m_r = floatToByte(rf);
    m_g = floatToByte(gf);
    m_b = floatToByte(bf);
    m_a = floatToByte(af);
}

Color::~Color()
{
}

string Color::toString() const
{
    ostringstream sout;
    sout << "Color[rgba](" << (short)m_r << "," << (short)m_g << "," << (short)m_b
         << "," << (short)m_a << ")";
    return sout.str();
}

}
